frontend/pages/e/[uuid]/index.tsx (view raw)
1import {PropsWithChildren} from 'react';
2import TravelColumns from '../../../containers/TravelColumns';
3import pageUtils from '../../../lib/pageUtils';
4import EventLayout from '../../../layouts/Event';
5import {EventByUuidDocument} from '../../../generated/graphql';
6import {getLocaleForLang} from '../../../lib/getLocale';
7import {getSession} from 'next-auth/react';
8
9interface Props {
10 eventUUID: string;
11 announcement?: string;
12}
13
14const Page = (props: PropsWithChildren<Props>) => {
15 return <EventLayout {...props} Tab={TravelColumns} />;
16};
17
18export const getServerSideProps = pageUtils.getServerSideProps(
19 async (context, apolloClient) => {
20 const {uuid} = context.query;
21 const {host = ''} = context.req.headers;
22 const session = await getSession(context);
23 let event = null;
24
25 const hasAcceptedTos = !!session?.profile?.tosAcceptationDate;
26 if (!hasAcceptedTos)
27 return {
28 redirect: {
29 destination: '/auth/confirm',
30 permanent: false,
31 },
32 };
33
34 // Fetch event
35 try {
36 const {data} = await apolloClient.query({
37 query: EventByUuidDocument,
38 variables: {uuid},
39 });
40 event = data?.eventByUUID?.data;
41 } catch (error) {
42 return {
43 notFound: true,
44 };
45 }
46
47 const description = await getLocaleForLang(
48 event?.attributes?.lang,
49 'meta.description'
50 );
51
52 return {
53 props: {
54 eventUUID: uuid,
55 metas: {
56 title: event?.attributes?.name || '',
57 description,
58 url: `https://${host}${context.resolvedUrl}`,
59 },
60 },
61 };
62 }
63);
64
65export default Page;